<?php
class Hydrum_Pathfinder_Path
{

    protected $_path;
    protected $_items;

    public function __construct($path)
    {
        $this->_path = $path;
    }

    public function lookup($regexp = null)
    {
        if (!$this->_items && is_dir($this->_path)) {

            $this->_items = new Hydrum_Pathfinder_Paths();

            $dir = new DirectoryIterator($this->_path);

            foreach ($dir as $file) {

                if ($file->isDot()) {
                    continue;
                }
                
                $path = $file->getPathname();
                
                if(!$regexp || preg_match('/' . $regexp . '/i', $path))
                {
                    $this->_items->addPath($path);
                }
            }
        }

        return $this->_items;
    }

    public function __toString()
    {
        return (string) $this->_path;
    }
}
